package C047;

import java.io.*;
import java.util.Arrays;
import java.util.Scanner;

/**
 * ClassName: C02
 * Package: C047
 * Description:
 *
 * @Author BCXJ
 * @Create 2025/2/9 09:36
 * @Version 1.0
 * @Since 1.0
 */
public class C02 {
    public static void main(String[] args) throws IOException {
        Scanner scan = new Scanner(System.in);
        int n, m;

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StreamTokenizer in = new StreamTokenizer(br);
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        while (in.nextToken() != StreamTokenizer.TT_EOF) {
            clear();
            n = (int) in.nval;
            in.nextToken();
            m = (int) in.nval;
            for (int i = 0, l, r, s, e; i < m; i++) {
                in.nextToken();
                l = (int) in.nval;
                in.nextToken();
                r = (int) in.nval;
                in.nextToken();
                s = (int) in.nval;
                in.nextToken();
                e = (int) in.nval;
                set(l, r, s, e);
            }
            long[] sumXor = getSumXor(n);
            long max = 0, xor = 0;
            for (int i = 1; i <= n; i++) {
                max = Math.max(max, ans[i]);
                xor ^= ans[i];
            }
            out.println(xor + " " + max);
        }
        out.flush();
        out.close();
        br.close();
    }

    private static void clear() {
        Arrays.fill(ans, 0);
    }


    private static long[] getSumXor(int n) {
        long sum = 0;
        // 二次求取前缀和
        for (int i = 1; i <= n; i++) {
            sum += ans[i];
            ans[i] = sum;
        }
        sum = 0;
        for (int i = 1; i <= n; i++) {
            sum += ans[i];
            ans[i] = sum;
        }
        long xor = 0;
        long max = Integer.MIN_VALUE;
        for (int i = 1; i <= n; i++) {
            xor ^= ans[i];
            max = Math.max(max, ans[i]);
        }
        return new long[]{xor, max};
    }

    static long[] ans = new long[10000002];

    private static void set(int l, int r, int s, int e) {
        int d = (e - s) / (r - l);
        ans[l] += s;
        ans[l + 1] += d - s;
        ans[r + 1] -= d+e;
        ans[r + 2] += e;
    }


}
